import 'package:encrypt/encrypt.dart';

/// key
final _key = Key.fromUtf8('eW9uZ2h1ZG91c2hpZGFzaGFiaS1mdWNr');

/// 偏移量
// final _iv = IV.fromLength(16);
final _iv = IV.fromUtf8('a0fe7c7c98e09e8c');

class EncryptUtil {
  /// 加密
  static String encrypt(String text) {
    var encrypter = Encrypter(
      AES(_key, mode: AESMode.cbc, padding: 'PKCS7'),
    );
    var encrypted = encrypter.encrypt(text, iv: _iv);
    return encrypted.base64;
  }

  /// 解密
  static String decrypt(Encrypted encrypted) {
    var encrypter = Encrypter(
      AES(_key, mode: AESMode.cbc, padding: 'PKCS7'),
    );
    return encrypter.decrypt(encrypted, iv: _iv);
  }
}
